//1599.经营摩天轮的最大利润
//https://leetcode.cn/problems/maximum-profit-of-operating-a-centennial-wheel/?envType=daily-question&envId=2024-01-01
class Solution {
public:
    int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) {
        if (4 * boardingCost < runningCost) return -1;
        int n = customers.size();
        int i = 0; //customers下标及次数
        int num = 0; //人数
        int m = 0; //当前金额
        int maxn = 0;
        int ret = 0;
        while (true)
        {
            if (i < n) num += customers[i];
            int player = min(num, 4); //获取当前上摩天轮人数
            num -= player;
            m += (player * boardingCost) - runningCost; //累计金额 每一趟的人支付金额 消耗的轮转金额
            if (maxn < m) maxn = m, ret = i + 1;
            if (i++ >= n && num == 0) break;
        }
        return ret == 0 ? -1 : ret;
    }
};